package com.itany.corejava.code06_面向对象.多态;

import java.util.Scanner;

/**
 * @author 石小俊
 * @date 2024年01月17日 8:47
 */
public class Pet {
    private String name;
    private String gender;

    public Pet() {
    }

    public Pet(String name, String gender) {
        this.name = name;
        this.gender = gender;
    }

    public void show() {
        System.out.println("这是一只宠物,名字叫做:" + name + ",性别:" + gender);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}

class Dog extends Pet {
    private int age;

    public Dog(String name, String gender, int age) {
        super(name, gender);
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void show() {
        System.out.println("这是一只宠物狗,其名字为:" + super.getName() + ",性别:" + getGender() + ",年龄:" + age);
    }
}

class Cat extends Pet {
    private String type;

    public Cat(String name, String gender, String type) {
        super(name, gender);
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void show() {
        System.out.println("这是一只" + type + "猫,名字:" + getName() + ",性别:" + getGender());
    }
}

class Pig extends Pet {
    private String hobby;

    public Pig(String name, String gender, String hobby) {
        super(name, gender);
        this.hobby = hobby;
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }

    public void show() {
        System.out.println("这是一只宠物猪,姓名:" + getName() + ",性别:" + getGender() + ",爱好:" + hobby);
    }
}

class TestPet {
    public static void main(String[] args) {
        showMenu();
    }

    public static void showMenu() {
        Scanner sc = new Scanner(System.in);
        System.out.println("************************欢迎来到南京紫金宠物店************************");

        while (true) {
            System.out.print("请选择想要领养的宠物(1.猫 2.狗 3.猪 4.退出):");
            int choice = sc.nextInt();
            Pet pet = null;
            switch (choice) {
                case 1:
                    System.out.print("请为您的宠物取一个昵称:");
                    String name = sc.next();
                    System.out.print("请选择你领养的宠物性别:");
                    String gender = sc.next();
                    System.out.print("请选择您想要领养的宠物猫的品种:");
                    String type = sc.next();
                    pet = new Cat(name, gender, type);
                    pet.show();
                    break;
                case 2:
                    System.out.print("请为您的宠物取一个昵称:");
                    name = sc.next();
                    System.out.print("请选择你领养的宠物性别:");
                    gender = sc.next();
                    System.out.print("请选择您想要领养的宠物狗的年龄:");
                    int age = sc.nextInt();
                    pet = new Dog(name, gender, age);
                    pet.show();
                    break;
                case 3:
                    System.out.print("请为您的宠物取一个昵称:");
                    name = sc.next();
                    System.out.print("请选择你领养的宠物性别:");
                    gender = sc.next();
                    System.out.print("请选择您想要领养的宠物猪的爱好:");
                    String hobby = sc.next();
                    pet = new Pig(name, gender, hobby);
                    pet.show();
                    break;
                case 4:
                    System.out.println("欢迎下次光临!");
                    return;
                default:
                    System.out.println("您输入的选项有误,请重新输入");
                    break;
            }
        }
    }
}